home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: Need to get value from 2-D matrix
- Date: 25 Mar 1996 20:10:59 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4j6ukj$pp7@sparcserver.lrz-muenchen.de>
- References: <DotDpo.6o2@news.uwindsor.ca>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- kima@uwindsor.ca (Sam Kim) writes:
-
-
- >I'm writing a program that reads in a 2-D matrix from binary. I am
- >useless with structures, so I'm trying to do this with arrays and
- >pointers.
-
- >Question : How do I read in the values?
-
- >I have :
-
- >for (i=0; i<n; i++)
- > for (j=0; j<n; j++)
- > {
- > fread(&ptr,1,1,fp)
-
- From this we can derive that
-
- a) "matrix" is a matrix of char (or any other quantity with the same size)
- b) "ptr" is a char (or ...)
-
- > matrix[i][j] = ptr;
-
- Is there a _real_ need for the intermediate variable "ptr". What prevents
-
- fread(&matrix[i][j], 1, 1, fp);
-
- Is there a _real_ need for reading the elements of the _inner_ array
- one at a time? Why not
-
- fread(matrix[i], 1, n, fp);
-
- This should work in all situations that allow you to use a double
- subscript.
-
- > ptr++;
-
- Is there a specific reason to increment an intermediate variable at
- this point? The next call to fread() will overwrite the value in ptr
- anyway.
-
- > }
-
- >Shouldn't this work?
-
- Yes, in fact it might work, given that my assumptions based on the
- code you showed us are true.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-
-